package finalproject.controller.commands;

import finalproject.model.items.Item;
import finalproject.model.player.Player;
import finalproject.view.StringManager;

/**
 * The use command
 * @author Buisson Kevin
 *
 */
public class UseCommand extends Command {

	/**
	 * 
	 * @param player the player issuing the command
	 * @param args the args of the command
	 */
	public UseCommand(Player player, String[] args)
	{
		super(player, args);
	}

	@Override
	public boolean process()
	{
		// No second word
		if (!hasSecondWord())
		{
			// if there is no second word, we don't know where to go...
			StringManager.outPut("noitem");
			return false;
		}

		// Hasn't the item
		Item held = getPlayer().getItemHolder().getHeldItem(getSecondWord());
		if (held == null)
		{
			StringManager.outPut("nosuchitem");
			return false;
		}

		// Use item
		held.use(getPlayer());
		return true;
	}

}
